package com.yxj.Test7Case;

import javax.swing.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.Callable;

public class MyCallable implements Callable<Integer> {
    ArrayList<Integer> list = new ArrayList<>();
    public MyCallable(ArrayList<Integer> list) {
        this.list = list;
    }
    @Override
    public Integer call() throws InterruptedException {
        ArrayList<Integer> BoxList = new ArrayList<>();//1  //2
        while (true) {
            synchronized (MyCallable.class) {
                if (list.size() == 0) {
                    System.out.println(Thread.currentThread().getName() + BoxList);
                    break;
                }else {
                    Collections.shuffle(list);
                    int price = list.remove(0);
                    BoxList.add(price);
                }
            }
            Thread.sleep(10);
        }
        //把集合中最大的值返回
        if(BoxList.size() == 0) {
            return null;
        }else {
            return Collections.max(BoxList);
        }
    }
}
